#pragma once
#include <boost/asio.hpp>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <string>

#include "AsioIOContextPool.h"
#include "CSession.h"

using tcp = boost::asio::ip::tcp;
using acceptor = boost::asio::ip::tcp::acceptor;
using namespace std;

class CSession;

class CServer {
 public:
  CServer(boost::asio::io_context& io_context, uint16_t port);
  ~CServer();
  void ClearSession(string session_id);

 private:
  void StartAccept();
  void HandleAccept(shared_ptr<CSession> session,
                    const boost::system::error_code& error);

 private:
  std::mutex _mutex;

  uint16_t _port;
  acceptor _acceptor;
  boost::asio::io_context& _io_context;
  std::map<string, shared_ptr<CSession>> _sessions;
};
